
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author 10045714
 */
public class LogWritter {

    private BufferedWriter accessLog;
    private BufferedWriter ordersLog;
    private BufferedWriter shipmentLog;

    public LogWritter(String accessLogPath, String ordersLogPath, String shipmentLogPath) throws IOException {
        this.accessLog = new BufferedWriter(new FileWriter(accessLogPath, true));
        this.ordersLog = new BufferedWriter(new FileWriter(ordersLogPath, true));
        this.shipmentLog = new BufferedWriter(new FileWriter(shipmentLogPath,true));
    }

    public synchronized void logAccess(String log) throws IOException {
        this.log(this.accessLog, log);
    }

    public synchronized void logOrder(String log) throws IOException {
        this.log(this.ordersLog, log);
    }

    public synchronized void logShipment(String log) throws IOException {
        this.log(this.shipmentLog, log);
    }

    private void log(BufferedWriter writer, String log) {
        try {
            writer.write(log);
            writer.newLine();
            writer.flush();
        } catch (IOException ex) {
            ex.printStackTrace();
            System.out.println("ERROR logging: " + log);
        }
    }

    public synchronized void close() {
        try {
            this.accessLog.close();
            this.ordersLog.close();
            this.shipmentLog.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}
